<?php

class CTableOperators
{

public static $instance; 

public static function getInstance()
	{
		//echo "<div id=register-box>";
        if(self::$instance==null)
		  self::$instance=new CTableOperators();
	//   echo "</div>";	  
		return  self::$instance;
	   
    
    }	


function DrawTable($title,$table,$campos)//obligatorio ID como campo inicial
    {
     
        
    $qu="select ";
    $i = 0;
    foreach($campos as $id=>$valor)
    {
    $qu=$qu."$id,";

    }
    $qu=substr($qu,0,strlen($qu)-1);
    $qu=$qu." from "."$table";
    
    echo "<div id='content_area_user_title'>";
    echo "<h2> $title</h2>";
    echo "</div>";


    echo	"<form>";						
    echo "<form id='filter-form'>Filter: <input name='filter' id='filter' value='' maxlength='30' size='30' type='text'></form><br>";
    echo "</form>";
   
    echo "<div class='usersettings_statistics'>"; 
 


    echo "<table class='food_planner'><thead><tr><th colspan='2'>Your Food List</th><tr></thead>";
    echo "<tbody><tr style='display: table-row;'>";


  
    foreach($campos as $id=>$valor){
  
    echo "<td><h3>$valor</h3></td>";
    
    }
    echo "<tr class='odd'>";
    foreach($campos as $id=>$valor){
  
    echo "<td><input type='text' name='$id' class='general-textarea'></td>";
    
    }
    
    // $qu="select*from $table";
    $table=CModelo::getInstance()->getData($qu);
//var_dump($table);
    $cont=0;
    $ruta=CConfig::getInstance()->rutalocal."/view";
    
    
    foreach($table as $campo => $valor)
    {$cont=$cont+1;
    if($cont%2){
        echo "<tr class='odd'>";
        $i="";$cont=0;
        foreach($valor as $id=>$val)
        { if($cont==0){$i=$val;}

        echo "<td width='10%'>$val</td>";$cont=$cont+1;
        }
        /*---------------------------------------------------------------------------*/
        // las referencias debbden de ser modificadas deacuerdo al directorio
        //
        /*---------------------------------------------------------------------------*/
        echo "<td> <a href='$ruta/CFillTable.php?codigo=$i'>Editar</a> </td>";
        echo "<td><a href='/edson1/modificar.php?codigo=$i'>Eliminar</a> </td>";
        echo "</tr>";
        }
        else
        {

        echo "<tr class='even'> ";
        $i2="";$cont2=0;
        foreach($valor as $id => $val)
        { if($cont2==0){$i2=$val;}
        echo "<td width='10%'>$val </td>";$cont2=$cont2+1;
        }
        echo "<td> <a href='$ruta/CFillTable.php?codigo=$i2'>Editar</a> </td>";
        echo "<td><a href='/edson1/modificar.php?codigo=$i2'>Eliminar</a> </td>";
        echo "</tr>";
        }
    
        }
        echo "</td></tr></tbody></table><br><br></form>";
        echo "</div>";
    } 
}
?>